package handin06;

/**
 * Product is the super class of the concrete products.
 * @author Peter Tolstrup Aagesen, ptaa@itu.dk
 *
 */
public class Product implements Valuable {

	//Variable for the value fo the product
	private double productValue;
	
	//Variable for the type of product
	private ProductType productType;
	
	/**
	 * Product constructor takes a value and a product type
	 * @param value double
	 * @param type ProductType
	 */
	public Product(double value, ProductType type)
	{
		//Set instance variables
		productValue = value;		
		productType = type;
	}
	
	/**
	 * getValue returns the value of the product
	 * @return product value
	 */
	public double getValue()
	{
		//Return
		return productValue;
	}
	
	/**
	 * ProductType returns the type of the product
	 * @return type of product
	 */
	public ProductType getType()
	{
		//Return
		return productType;
	}
	
	/**
	 * Returns a String describing the state of the product
	 */
	public String toString()
	{		
		//Format ProductType 
		String type = productType.toString().substring(0, 1) + productType.toString().substring(1).toLowerCase();
		
		//Return
		return "This is a " + type + " Product worth " + productValue;
	}
	
	@Override
	public boolean equals(Object c) {
		boolean returnValue = false;
		if(this == c){
			returnValue = true;
		} else if(c instanceof Product){
			Product other = (Product) c;
			if(other.getType() == this.productType && other.getValue() == this.productValue)
			{
				returnValue = true;				
			}
		}
		return returnValue;
	}
}
